package filter; /**
 * ${PACKAGE_NAME}.${NAME}
 * User: huangly
 * Date: 2024/11/22 9:28
 * motto:   逆水行舟不进则退
 * Description:
 * Version: v1.0
 */

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;
//拦截所有的请求
@WebFilter(filterName = "CharacterEncodingFilter",urlPatterns = "/*")//login.jsp
public class CharacterEncodingFilter implements Filter {
    public void init(FilterConfig config) throws ServletException {
        System.out.println("====初始化配置信息=====");
    }
    public void destroy() {
        System.out.println("====销毁=====");
    }

    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
         request.setCharacterEncoding("utf-8");
         response.setCharacterEncoding("utf-8");
         System.out.println("====设置字符集为  UTF-8====");
         //进入目标地址 或者叫进入下一个过滤
         chain.doFilter(request, response);
    }
}
